<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <#assign base=request.contextPath  />
    <#setting  number_format="0.##"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>收货地址</title>
    <link href="${base}/sweep/css/mui.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="${base}/sweep/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="${base}/sweep/css/app.css"/>
    <link rel="stylesheet" type="text/css" href="${base}/sweep/icon/iconfont.css"/>
    <script src="${base}/backstage/js/jquery.js"></script>
    <script src="${base}/sweep/icon/iconfont.js"></script>
    <script src="${base}/sweep/js/mui.min.js"></script>
    <style>
        .mui-switch:before
        {
            position: absolute;
            top: 0px;
        }
        #moRenAddress{
            height: 26px;
            width: 73px;
            padding: 0px;
            margin: 0px;
            /* position: relative; */
            /* bottom: 0px; */
            background: red;
            color: #fff;
        }
    </style>
</head>
<body>
<div class="mui-content">
    <#list address as address>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media">
                <a href="javascript:;">
                    <div class="mui-media-body">
                        ${address.name}
                        ${address.phone}
                        <p class='mui-ellipsis'>${address.address}${address.xi}</p>
                    </div>
                </a>
                <a>
                    <div class="mui-media-body" style="float: right;">
                        <#if address.state==1>
                            <button type="button" class="layui-btn layui-btn-danger layui-btn-radius" id="moRenAddress">默认地址</button>
                        </#if>
                        <#if address.state==2></#if>
                        <span class="mui-icon mui-icon-compose" onclick="updateByIdAddress('${address.id}')"
                              style="font-size: 15px;color: #9F9F9F">编辑</span>
                        <span class="mui-icon mui-icon-trash" onclick="deleteAddress('${address.id}')"
                              style="font-size: 15px;color: #9F9F9F">删除</span>
                    </div>

                </a>
            </li>
<#--            <li class="mui-table-view-cell mui-media">-->


<#--            </li>-->
        </ul>

    </#list>


</div>

<div class="mui-content" style="position: absolute;bottom: 0px;width: 100%">
    <div class="mui-content-padded">
        <button type="button" class="mui-btn mui-btn-warning mui-btn-block" onclick="window.location.href='${base}/wx/address/newAddress.html?userId=${user.id}'">新建地址</button>
    </div>
</div>

</body>
<script>
<#-- 编辑 -->
function updateByIdAddress(id) {
    window.location.href="${base}/wx/address/updateAddress.html?id="+id
}


/*修改状态*/
function stateAddress(id) {
    $.ajax({
        type: "POST",
        url: "${base}/wx/address/updateState",
        data: {id:id},
        success: function (data) {
            if (data.code === 200) {
                mui.toast(data.msg);
                window.location.href = "${base}/wx/user/address.html"
            } else {
                mui.toast(data.msg);
            }
        }
    });
}
/*删除地址*/
    function deleteAddress(id) {
        $.ajax({
            type: "POST",
            url: "${base}/wx/address/deleteById",
            data: {id:id},
            success: function (data) {
                if (data.code === 200) {
                    mui.toast(data.msg);
                    window.location.href = "${base}/wx/user/address.html"
                } else {
                    mui.toast(data.msg);
                }
            }
        });
    }
    mui.init();

</script>
</html>